package com.wms.service.impl;

import com.wms.entity.WMSFile;
import com.wms.mapper.UploadMapper;
import com.wms.service.UploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * ---Do First---
 *
 * @author:wellseasun
 * @date:2025/4/29 下午 1:58
 * @desc:
 */
@Service
public class UploadServiceImpl implements UploadService {
    @Autowired
    UploadMapper uploadMapper;

    @Override
    public void upload(String filePath) {
        // 分割路径并获取最后两位
        List<String> pathSegments = Arrays.asList(filePath.split("/"));
        int size = pathSegments.size();

        // 安全获取最后两个元素（当元素不足两个时取全部）
        List<String> lastTwoSegments = pathSegments.subList(
                Math.max(size - 2, 0),  // 起始索引不小于0
                size
        );
        // 合并为字符串（可根据需要修改连接符）
        String result = String.join("/", lastTwoSegments);

        uploadMapper.upload(result);

    }

    @Override
    public List<WMSFile> list() {
        return uploadMapper.list();
    }
}
